package com.lframework.xingyun.basedata.impl.product;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
import com.lframework.xingyun.basedata.entity.ProductCostCardDetail;
import com.lframework.xingyun.basedata.mappers.ProductCostCardDetailMapper;
import com.lframework.xingyun.basedata.service.product.ProductCostCardDetailService;

import java.util.Collections;
import java.util.List;
import org.springframework.stereotype.Service;

/**
 * 商品成本卡明细服务实现
 *
 * @author zmj
 * @since 2024-01-01
 */
@Service
public class ProductCostCardDetailServiceImpl extends BaseMpServiceImpl<ProductCostCardDetailMapper, ProductCostCardDetail>
    implements ProductCostCardDetailService {

  @Override
  public List<ProductCostCardDetail> getByCostCardId(String costCardId) {

    LambdaQueryWrapper<ProductCostCardDetail> wrapper = new LambdaQueryWrapper<>();
    wrapper.eq(ProductCostCardDetail::getCostCardId, costCardId);
    wrapper.eq(ProductCostCardDetail::getType, 0);
    wrapper.orderByAsc(ProductCostCardDetail::getOrderNo);

    return this.list(wrapper);
  }

  @Override
  public List<ProductCostCardDetail> getReplacementsByCostCardId(String costCardId) {
      LambdaQueryWrapper<ProductCostCardDetail> wrapper = new LambdaQueryWrapper<>();
      wrapper.eq(ProductCostCardDetail::getSourceProductId, costCardId);
      wrapper.eq(ProductCostCardDetail::getType, 1);
      wrapper.orderByAsc(ProductCostCardDetail::getOrderNo);

      return this.list(wrapper);
  }

  @Override
  public void deleteByCostCardId(String costCardId) {

    LambdaQueryWrapper<ProductCostCardDetail> wrapper = new LambdaQueryWrapper<>();
    wrapper.eq(ProductCostCardDetail::getCostCardId, costCardId);

    this.remove(wrapper);
  }

  @Override
  public List<ProductCostCardDetail> getByIngredientProductId(String ingredientProductId) {

    LambdaQueryWrapper<ProductCostCardDetail> wrapper = new LambdaQueryWrapper<>();
    wrapper.eq(ProductCostCardDetail::getIngredientProductId, ingredientProductId);

    return this.list(wrapper);
  }
} 